package org.wattdepot.cli;

//import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;

/**
 * Test class for CommandLineInterfaceTest.
 * 
 * @author Dean Kim
 * 
 */
public class TestCommandLineInterfaceTest {

  CommandLineInterface cli;
  private static final String HELP = "HELP";
  private static final String QUIT = "QUIT";
  private static final String LIST = "LIST";
  private static final String NONVALID = "NONVALID";

  /**
   * Initializes class for testing.
   */
  @Before
  public void initializeCommandLineInterface() {
    cli = new CommandLineInterface("http://server.wattdepot.org:8182/wattdepot/");
  }

  /**
   * Junit test for the processMaincommand.
   */
  @Test
  public void testProcessMainCommand() {

    final String listSourcesError = "Invalid sources command. Type help for usage.";
    final String chartPowerError = "chart power error. Usage: chart power "
        + "[generated|consumed] {source} {startday} {endday} sampling-interval {minutes} "
        + "file {filename}";
    final String listTotalError = "total usage error. Usage: total "
        + "[carbon|energy] {source} day {day} sampling-interval {minutes}";
    assertEquals("Test assert equals:", cli.processMainCommand("no_command"), "Invalid"
        + " command. Type Help for a list of commands.");
    assertEquals("Test quit command: ", cli.processMainCommand("QUIT"), "Exit");
    // Following set of tests ensure various command interfaces don't break.
    assertEquals("Test invalid source summary return",
        cli.processMainCommand("SOURCE SIM_GGG SUMMARY"), "Invalid source.\n");
    assertEquals("Test invalid sources", cli.processMainCommand("SOURCES INVALID"),
        listSourcesError);
    assertEquals("Test invalid total", cli.processMainCommand("TOTAL CARBON INVALID"),
        listTotalError);
    assertEquals("Test invalid chart power", cli.processMainCommand("CHART POWER GENERATED"),
        chartPowerError);
  }

  /**
   * Unit test checking both valid and nonvalid commands passed to isValidCommand.
   */
  @Test
  public void testIsValidCommand() {

    assertEquals("Test isValidCommand HELP", cli.isValidCommand(HELP), true);
    assertEquals("Test isValidCommand QUIT", cli.isValidCommand(QUIT), true);
    assertEquals("Test isValidCommand LIST", cli.isValidCommand(LIST), true);
    assertEquals("Test isValidCommand LIST", cli.isValidCommand(NONVALID), false);

  }
}
